//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Graphics/Primitives/Vertices.h"
#include "Graphics/Primitives/Indices.h"

namespace Engine
{
namespace Primitives
{

	//
	// Line 2D
	//

	template <typename Vert>
	struct Line2D : LineIndices
	{
	// types
	public:
		typedef Vert			vertex_t;
		typedef Line2D< Vert >	Self;


	// variables
	public:
		LineVertex2D	begin,
						end;
		
	// methods
	public:
		Line2D ()
		{}

		Line2D (const vertex_t &begin, const vertex_t &end) :
			begin(begin), end(end)
		{}
			
		static uint VerticesCount ()
		{
			return 2;
		}

		void GetVertices (void *data) const
		{
			MemCopy( data, this, sizeof(*this) );
		}

		int ScissorTest (const rect &scissorRect) const
		{
			if ( scissorRect.IsInnerLine( line2d( begin.position, end.position ) ) )
				return 0;	// fully visible

			if ( scissorRect.IntersectLine( line2d( begin.position, end.position ) ) )
				return 1;	// crop

			return -1;	// cut
		}

		Self Crop (const rect &scissorRect) const
		{
			Self	result = *this;

			bool	res = scissorRect.GetLineIntersection( line2d( begin.position, end.position ),
														result.begin.position, result.end.position );
			ASSERT( res );

			TODO("line crop");

			return result;
		}

	};
	
	typedef Line2D< LineVertex2D >		ColoredLine2D;


}	// Primitives
}	// Engine
